/**
 * 封装axios，对全局请求统一处理
 */

import axios from "axios";

const requests = axios.create({
  // baseURL: "",
  timeout: 10000,
});

// 请求拦截器
requests.interceptors.request.use(
  (config) => {
    // 附加token
    // config.headers.Authorization = window.sessionStorage.getItem('token')

    return config;
  },
  (error) => {
    // 请求失败
    return Promise.reject(error);
  }
);

// 响应拦截器
requests.interceptors.response.use(
  (res) => {
    // 响应成功
    return res.data;
  },
  (error) => {
    // 响应失败
    return Promise.reject(error);
  }
);

export const CancenToken = axios.CancelToken 

export default requests;
